
function block_get_setting(classname, script, bid) {
	var x = new Ajax();
	x.get('index.php?option=block&op=setting&bid='+bid+'&classname='+classname+'&script='+script+'&inajax=1', function(s){
		ajaxinnerhtml('tbody_setting', s);
	});
}

function showpicedit() {
	if($('#picway_remote')[0].checked) {
		$('#pic_remote').show();
		$('#pic_upload').hide();
	} else {
		$('#pic_remote').hide();
		$('#pic_upload').show();
	}
}

function block_show_thumbsetting(classname, styleid, bid) {
	var x = new Ajax();
	x.get('index.php?option=block&op=thumbsetting&classname='+classname+'&styleid='+styleid+'&bid='+bid+'&inajax=1', function(s){
		ajaxinnerhtml('tbody_thumbsetting', s);
	});
}

function block_showstyle(stylename) {
	var el_span = $$$('span_'+stylename);
	var el_value = $$$('value_' + stylename);
	if (el_value.value == '1'){
		el_value.value = '0';
		el_span.className = "";
	} else {
		el_value.value = '1';
		el_span.className = "a";
	}
}

function block_pushitem(bid, itemid) {
	var id = $$$('push_id').value;
	var idtype = $$$('push_idtype').value;
	if(id && idtype) {
		var x = new Ajax();
		x.get('index.php?option=block&op=push&&bid='+bid+'&itemid='+itemid+'&idtype='+idtype+'&id='+id+'&inajax=1', function(s){
			ajaxinnerhtml('tbody_pushcontent', s);
		});
	}
}

function block_delete_item(bid, itemid, itemtype, from) {
	var msg = itemtype==1 ? JSLANG['deldata'] : JSLANG['hidedata'];
	if(confirm(msg)) {
		var url = 'index.php?option=block&op=remove&bid='+bid+'&itemid='+itemid;
		if(from=='ajax') {
			var x = new Ajax();
			x.get(url+'&inajax=1', function(){
				showWindow('showblock', 'index.php?option=block&op=data&bid='+bid+'&tab=data&t='+(+ new Date()), 'get', 0);
			});
		} else {
			location.href = url;
		}
	}
	doane();
}

function comment_requote(cid) {
	var x = new Ajax();
	x.get('index.php?option=comment&task=requote&cid='+cid+'&inajax=1', function(s){
		$$$('message').focus();
		ajaxinnerhtml('message', s);
	});
}
function insertQuote(s){
	insertContent('message', s);
}
function insertImage(text) {
	text = "\n[img]" + text + "[/img]\n";
	insertContent('message', text)
}

function insertContent(target, text) {
	var obj = $$$(target);
	selection = document.selection;
	checkFocus(target);
	if(!isUndefined(obj.selectionStart)) {
		var opn = obj.selectionStart + 0;
		obj.value = obj.value.substr(0, obj.selectionStart) + text + obj.value.substr(obj.selectionEnd);
	} else if(selection && selection.createRange) {
		var sel = selection.createRange();
		sel.text = text;
		sel.moveStart('character', -strlen(text));
	} else {
		obj.value += text;
	}
}


function checkFocus(target) {
	var obj = $$$(target);
	if(!obj.hasfocus) {
		obj.focus();
	}
}

function getColorPalette(colorid, id, background) {
	return "<input id=\"c"+colorid+"\" onclick=\"createPalette('"+colorid+"', '"+id+"');\" type=\"button\" class=\"colorwd\" value=\"\" style=\"background: "+background+"\">";
}

function listblock_bypage(tpl) {
	var msg = '';
	var sel = $$$('recommend_bid');
	var elem = $$$('recommend_pageblock_' + tpl);
	sel.options.length = 0;
	sel.options.add(new Option(JSLANG['selblock'], ''));
	if(elem && elem.options.length) {
		msg = JSLANG['finded']+'<font color="red">'+elem.options.length+'</font>'+JSLANG['blocks'];
		for(var i=0; i<elem.options.length; i++) {
			var opt = elem.options[i];
			sel.options.add(new Option(opt.text, opt.value));
		}
	} else {
		msg = '<font color="red">'+JSLANG['noblock']+'</font>';
	}
	ajaxinnerhtml('itemeditarea', '<tr><td>&nbsp;</td><td>&nbsp;'+msg+'</td></tr>');
}

function recommenditem_check() {
	var sel = $$$('recommend_bid');
	if(sel && sel.value) {
		return true;
	} else {
		alert(JSLANG['plsselblock']);
		return false;
	}
}

function recommenditem_byblock(bid, id, idtype) {
	if($('#itemeditarea')) {
		if(bid) {
			ajaxget('index.php?option=block&op=recommend&bid='+bid+'&id='+id+'&idtype='+idtype+'&handlekey=recommenditem', 'itemeditarea');
		} else {
			ajaxinnerhtml('itemeditarea', '<tr><td>&nbsp;</td><td>&nbsp;</td></tr>');
		}
	}
}

function blockSetCacheTime(timer) {
	$$$('txt_cachetime').value=timer;
	doane();
}

function toggleSettingShow() {
	if(!$$$('tbody_setting').style.display) {
		$$$('tbody_setting').style.display = 'none';
		$$$('a_setting_show').innerHTML = JSLANG['showsetting'];
	} else {
		$$$('tbody_setting').style.display = '';
		$$$('a_setting_show').innerHTML = JSLANG['hiddensetting'];
	}
	doane();
}

function checkblockname(form) {
	if(!(trim(form.name.value) > '')) {
		alert(JSLANG['emptyblockid']);
		form.name.focus();
		return false;
	}
	return true;
}

function blockconver(ele,bid) {
	if(ele && bid) {
		if(confirm(JSLANG['changeblock']+ele.options[0].innerHTML+JSLANG['to']+ele.options[ele.selectedIndex].innerHTML)) {
			ajaxget('index.php?option=block&op=convert&bid='+bid+'&toblockclass='+ele.value,'blockshow');
		} else {
			ele.selectedIndex = 0;
		}
	}
}
